package com.example.train_operate.controller;

import com.example.train_operate.service.FileService;
import com.example.train_operate.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping("/upload")
@CrossOrigin
@Api(tags = "OSS文件上传接口")
public class FileController {

    @Resource
    private FileService fileService;

    /**
     * 文件上传至阿里云
     * @param file
     * @return
     */
    @PostMapping("/oss")
    @ApiOperation("图片上传至阿里云")
    public Result ossUpload(@RequestBody MultipartFile file){
        return fileService.uploadFileToOss(file);
    }

    /**
     * 文件上传至本地
     * @param file
     * @return
     */
    @PostMapping("/local")
    @ApiOperation("图片上传至本地")
    public Result localUpload(@RequestBody MultipartFile file){
        return fileService.uploadFileToLocal(file);
    }
}
